<%@ page contentType="text/html;charset=utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>组织机构添加</title>
		<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/web/style/layout4.css" />
		<script type="text/javascript" src="<%=request.getContextPath() %>/jqGrid/js/jquery-1.7.2.min.js"></script>
	    <script type="text/javascript" src="<%=request.getContextPath() %>/jslib/jquery.validate.min.js"></script>
	    <script type='text/javascript' src="<%=request.getContextPath() %>/jslib/jquery.form.js"></script>
	    <script type="text/javascript" src="<%=request.getContextPath() %>/jslib/additional-methods.js"></script>
		<style type="text/css">
			.tdtitle
			{
				background-color:#b7dbf3;
				text-align:center;
				height:20px;
				font-size:15px;
				font-weight:bold;
			}
			
		</style>
		<c:if test="${requestScope.message!=null}">
			<script type="text/javascript">
  	 		     alert('<c:out value="${requestScope.message}"></c:out>');
  			</script>
	    </c:if>
		<script type="text/javascript"> 
			var api = frameElement.api, W = api.opener;
			function init()
			{
				var orgParentId = document.getElementById("orgParentId");
				var orgParentIdsName = document.getElementById("orgParentIdsName");
				orgParentId.value = eval("(" + api.data + ")").orgParentId;
				orgParentIdsName.value = eval("(" + api.data + ")").orgParentIdsName;
			}
		    $().ready(function() {
		 
		    	// 准备好Options对象
		    	var options = {
		    	    url:'saveOrganization.action',
		    	    beforeSubmit: checkForm,
		    	    dataType:'json',
		    	    success: function(data) {
		    	      if(data.ajaxResult=='success'){
							alert("添加成功");
							api.close();
							W.reload();
		    	      }else if (data.ajaxResult=='have'){
		    	    	  alert(eval("(" + api.data + ")").orgParentIdsName+"下已存在该组织机构名称");
		    	    	  $("#orgName").focus();
		    	      } else if (data.ajaxResult=='haveparent'){
		    	    	  alert("与选择的树节点的组织机构名称重复");
		    	    	  $("#orgName").focus();
		    	      } 
		    	}};
				$('#submitBtn').click(function(){
					$('#pageFrom input').keyup(trimkeyup);
					//表单提交
			    	$('#pageFrom').ajaxSubmit(options);
			            return false;
		    	 });
				$('#cancelBtn').click(function(){
					api.close();
		    	 });
		    });
		    function checkForm(){
				var flag = true;
				
				/*if($.trim($("#orgNo").val()) == ""){
					alert("请填写组织机构编号!");
					$("#orgNo").focus();
					return false;
				}*/
				if($.trim($("#orgNo").val()) != "")
				{
					if(!checkExp1($("#orgNo").val())){
						alert("组织机构编号不能含有如下特殊符号：\" # $ \, \' \\");
						$("#orgNo").focus();
						return false;
					}else if(!orgNoCountintlen($("#orgNo").val())){
						alert("组织机构编号最多为40个字符,字符输入超出限制!");
						$("#orgNo").focus();
						return false;
					}else if(!(flag = checkorgNo())){
						$("#orgNo").focus();
						return false;
					}	
				}
				
				
				if($.trim($("#orgName").val()) == ""){
					alert("请填写组织机构名称!");
					$("#orgName").focus();
					return false;
				}else if(!checkExp2($("#orgName").val())){
					alert("组织机构名称不能含有如下特殊符号：\" # $ \, \' \\ \{");
					$("#orgName").focus();
					return false;
				}else if(!orgNameCountintlen($("#orgName").val())){
					alert("组织机构名称最多为40个字符,字符输入超出限制!");
					$("#orgName").focus();
					return false;
				}
				
				/*if(!checkExp1($("#departmentAs").val())){
					alert("组织机构简称不能含有如下特殊符号：\" # $ \, \' \\");
					$("#departmentAs").focus();
					return false;
				}else if(!departmentAsCountintlen($("#departmentAs").val())){
					alert("组织机构简称最多为40个字符,字符输入超出限制!");
					$("#departmentAs").focus();
					return false;
				}
				
				if(!checkExp1($("#orgDesc").val())){
					alert("组织机构说明不能含有如下特殊符号：\" # $ \, \' \\");
					$("#orgDesc").focus();
					return false;
				}else if(!orgDescCountintlen($("#orgDesc").val())){
					alert("组织机构说明最多为40个字符,字符输入超出限制!");
					$("#orgDesc").focus();
					return false;
				}*/
			}
		    //过滤表单的前后空格
			function trimkeyup(e) {
			     lucene_objInput = $(this);
			     if (e.keyCode != 38 && e.keyCode != 40 && e.keyCode != 13) {
			        var im = $.trim(lucene_objInput.val());
			       lucene_objInput.val(im); 
			    }
			} 
		    //验证特殊字符
			function checkExp(inputData){ 
				//var regEx = new RegExp(/^(([^\^\.<>%&',:;=?$"'#@!~\]\[{}【】￥（）！·‘’”“。，、？：；—|\/\\/`\|])*)$/);
				var regEx = new RegExp(/^(([^$,"'#])*)$/);
				var result = inputData.match(regEx);
				if (result == null) {
				return false;
				}
				return true;
			}
		    //验证特殊字符
			function checkExp1(inputData){ 
				//var regEx = new RegExp(/^(([^\^\.<>%&',:;=?$"'#@!~\]\[{}【】￥（）！·‘’”“。，、？：；—|\/\\/`\|])*)$/);
				var regEx = new RegExp(/^(([^$,"'#\\])*)$/);
				var result = inputData.match(regEx);
				if (result == null) {
				return false;
				}
				return true;
			}
		    //验证特殊字符
			function checkExp2(inputData){ 
				//var regEx = new RegExp(/^(([^\^\.<>%&',:;=?$"'#@!~\]\[{}【】￥（）！·‘’”“。，、？：；—|\/\\/`\|])*)$/);
				var regEx = new RegExp(/^(([^$#,"'{\\])*)$/);
				var result = inputData.match(regEx);
				if (result == null) {
				return false;
				}
				return true;
			}
		    //验证唯一性
		    function checkorgNo(){
				var flag = true;
				
				$.ajax({
				   type: "POST",
				   async: false,//取消异步提交
				   url: "findOrganizationByorgNo.action",
				   dataType: "json",
				   data: {
				   		orgNo: function(){
							return encodeURIComponent($("#orgNo").val());
						}
				   },
				   success: function(data){
				   	 if(data.result != "success"){
				     	alert( "已存在该组织机构编号!" );
				     	flag = false;
				     }
				   }
				}); 
				return flag;
			}
		    //验证input长度
			function orgNoCountintlen(input){
				var result = $("#orgNo").val().length;
				if (result > 40) {
					return false;
				}else{
					return true;
				}
			}
		    function departmentAsCountintlen(input){
				var result = $("#departmentAs").val().length;
				if (result > 40) {
					return false;
				}else{
					return true;
				}
			}
			function orgNameCountintlen(input){
				var result = $("#orgName").val().length;
				if (result > 40) {
					return false;
				}else{
					return true;
				}
			}
			function orgDescCountintlen(input){
				var result = $("#orgDesc").val().length;
				if (result > 40) {
					return false;
				}else{
					return true;
				}
			}
		   
			
		</script>
		<style type="text/css">
			 body{background:#ffffff; background-image:url(images/);}
		   		html{   
				    overflow-x: hidden; 
					overflow-y: hidden;
					}  		
	    </style>
	 </head>
	<body onload="init()">
	<form id="pageFrom" action="" name="" method="post">
	<input type="hidden" id="orgParentId" name="orgParentId"/>
	<!--表单开始-->
	<table width="100%" border="0" align="center" cellpadding="5" cellspacing="5" class="formTableNew">
	  <tr>
	    <td align="right">父机构名称：</td>
	    <td align="left">
		    <div class="div">
				<input id="orgParentIdsName" name="orgParentIdsName" readonly="readonly" onkeydown="if(event.keyCode==8)return false;"/>
			</div>
	    </td>
	  </tr>
	  <tr>
	    <td align="right">组织机构编号：</td>
	    <td> 
		    <div class="div">
				<input id="orgNo" name="orgNo" />
                <!-- <img src="<%=request.getContextPath() %>/images/xh.png"></img>  -->
			</div>
	    </td>
	  </tr>
	  <tr>
	    <!--  <td align="right">组织机构名称：</td>-->
	    <td align="right">单位名称：</td>
	    <td> 
		    <div class="div">
				<input id="orgName" name="orgName" />
                <img src="<%=request.getContextPath() %>/images/xh.png"></img>
			</div>
	    </td>
	  </tr>
	  <tr>
	    <td align="right">单位资质：</td>
	    <td> 
		    <div class="div">
				<input id="unitAptitude" name="unitAptitude"  style="width:215px"></input>
			</div>
	    </td>
	  </tr>
	   <tr>
	    <td align="right">资质等级：</td>
	    <td> 
		    <div class="div">
				<input id="unitLevel" name="unitLevel"  style="width:215px"></input>
			</div>
	    </td>
	  </tr>
	   <tr>
	    <td align="right">单位地址：</td>
	    <td> 
		    <div class="div">
				<input id="unitAddr" name="unitAddr"  style="width:215px"></input>
			</div>
	    </td>
	  </tr>
	   <tr>
	    <td align="right">邮政编码：</td>
	    <td> 
		    <div class="div">
				<input id="unitPostcode" name="unitPostcode"  style="width:215px"></input>
			</div>
	    </td>
	  </tr>
	   <tr>
	    <td align="right">单位规范：</td>
	    <td> 
		    <div class="div">
				<input id="unitStandard" name="unitStandard"  style="width:215px"></input>
			</div>
	    </td>
	  </tr>		
	   <tr>
	    <td align="right">单位类别：</td>
	    <td> 
		    <div class="div">		    
				<!--  <input id="unitType" name="unitType"  style="width:215px"></input> -->
				<select id="unitType" name="unitType" >
				 <option value ="设计单位">设计单位</option>
				 <option value ="建设单位">建设单位</option>
				 <option value ="施工单位">施工单位</option>
				 <option value ="监理单位">监理单位</option>
				 <option value ="无损检测单位">无损检测单位</option>
				 <option value ="防腐单位">防腐单位</option>
				 <option value ="阴保单位">阴保单位</option>				
				 <option value ="填写单位">填写单位</option>
				 <option value ="管理单位">管理单位</option>
				 <option value ="制造单位">制造单位</option>
				 <option value ="安装单位">安装单位</option>
				 <option value ="违法单位">违法单位</option>
				 <option value ="检测单位">检测单位</option>
				 <option value ="受检单位">受检单位</option>
				 <option value ="使用单位">使用单位</option>
				 <option value ="评估单位">评估单位</option>
				</select>
			</div>
	    </td>
	  </tr>				
	  <!--  <tr>
	    <td align="right">组织机构简称：</td>
	    <td> 
		    <div class="div">
				<input id="departmentAs" name="departmentAs" />
			</div>
	    </td>
	  </tr>
	  <tr>
	    <td align="right">组织机构说明：</td>
	    <td>
	    	<div class="div">
				<input id="orgDesc" name="orgDesc" />
			</div>	
	    </td>
	  </tr>
	  <tr>
	    <td align="right">组织机构排序：</td>
	    <td>
	    	<div class="div">
				<input id="orgOrder" name="orgOrder" />
			</div>	
	    </td>
	  </tr>
	  <tr>
	    <td align="right">组织机构前缀：</td>
	    <td>
	    	<div class="div">
				<input id="orgPrex" name="orgPrex" />
			</div>	
	    </td>
	  </tr>
	  -->
	 <tr>
	    <td align="center" colspan="2" >
	    	<input type="button" id="submitBtn" value="保 存" class="form_bt_orange" />
	      	<input type="button" id="cancelBtn" value="关 闭" class="form_bt_grey" />
	    </td>
	  </tr>
	</table>
	<!--表单结束-->
  </form>
  </body>
</html>
